<?php defined('BASEPATH') OR exit('No direct script access allowed');

class auth_class extends CI_Model {

	public function is_id_isset()
	{
		$intUserID = $this->session->userdata('intUserID');
		
		$result = $intUserID == '' && $this->is_cookie_isset() == 0 ? 0 : 1;
		
		return $result;
	}
	public function is_cookie_isset()
	{
		$myCookie = get_cookie('intUserID');
		
		$result = $myCookie == '' ? 0 : 1;
		
		return $result;
	}
	public function is_session_active()
	{
		$intUserID = $this->session->userdata('intUserID');
		
		return $intUserID != '' && $this->is_cookie_isset() == 1 ? TRUE:FALSE;
	}
	public function update_session($thsess, $intUserID)
	{
		$thsess = stripslashes(filter_var($thsess, FILTER_SANITIZE_STRING));

		$this->db->where(array('strSessionKey'=>$thsess, 'strSessionOwner'=>$intUserID)); 
		$this->db->update('th_sessions', array('timeInSession'=>time()));
	}
	public function get_session($thsess, $intUserID)
	{
		$thsess = stripslashes(filter_var($thsess, FILTER_SANITIZE_STRING));
		
		$this->db->select('*');
		$this->db->from('th_sessions');
		$this->db->where(array('strSessionKey'=>$thsess, 'strSessionOwner'=>$intUserID)); 
		$query = $this->db->get()->result_array();
		$query = current($query);
		
		if($query['intSessionID']==""){
			return 0;
		} else {
			return $query;
		}
	}
}